package org.vectrics.recruiter.struts.admin;

import javax.servlet.jsp.JspException;

import org.apache.log4j.Logger;
import org.vectrics.history.HistoryProvider;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.job.Job;
import org.vectrics.struts.Request;
import org.vectrics.struts.VectricsActionData;
import org.vectrics.struts.VectricsStrutsAction;
import org.vectrics.user.Person;


public class RemoveJobAction extends VectricsStrutsAction {
    private transient final Logger log = Logger.getLogger(this.getClass());
    public static String ACTION_NAME = "rmv_job";
    public static String JOB_PARAM = "job";    
    

    public RemoveJobAction() {
    	//
    }

	public String doExecute(VectricsActionData actionData)	throws JspException {
        log.debug("doPerform() called");
		Request request = actionData.getRequest();
        
        String jobIdParam = request.getParameter("jobId");
        Long jobId = new Long(jobIdParam);
        boolean cancelButtonPressed = actionData.wasButtonPressed("cancel");
 
        if (!cancelButtonPressed) {
            log.debug("doPerform() submit button pressed - removing..");
            try {
            	Person authPerson = actionData.getAuthPerson();
                Job job = RecruitServiceLocator.getJobProvider().findJob(jobId);
                job.setVoided(true);
                RecruitServiceLocator.getJobProvider().updateJob(job);
                HistoryProvider.getInstance().createHistory(Job.OBJECT_TYPE, jobId.toString(), 
                        "job_void", authPerson, actionData.getPhrase("activity.job.remove"));
                
            }
            catch (Exception re) {
                log.error("doPerform() - exception removing job: " + jobId, re);
            }
        }
        else {
            log.debug("cancel pressed, no action.");
        }
		return ("success");
        
    }

}
